package easy;

import util.PrintUtils;

public class Solution_1720 {
    public int[] decode(int[] encoded, int first) {
        int[] array = new int[encoded.length + 1];
        array[0] = first;
        for (int i = 0; i < encoded.length; i++) {
            int val = 0;
            int a = array[i];
            int b = encoded[i];
            int mul = 1;
            while (a > 0 || b > 0) {
                int m = a % 2;
                int n = b % 2;
                if (n == 0) {
                    val += (m * mul);
                } else {
                    val += (Math.abs((m - 1)) * mul);
                }
                a >>= 1;
                b >>= 1;
                mul <<= 1;
            }
            array[i + 1] = val;
        }
        return array;
    }

    public static void main(String[] args) {
        Solution_1720 model = new Solution_1720();
        PrintUtils.arrayInt(model.decode(new int[]{1, 2, 3}, 1));
        PrintUtils.arrayInt(model.decode(new int[]{6,2,7,3}, 4));
    }
}
